package com.another.bidservice.service.impl;

import com.another.bidservice.entity.TCodeCur;
import com.another.bidservice.entity.TCodeRule;
import com.another.bidservice.dao.mapper.CodeCurDao;
import com.another.bidservice.service.ICodeCurService;
import com.another.common.utils.common.EmptyUtil;
import com.another.common.utils.common.MyException;
import com.another.common.utils.result.Result;
import com.another.bidservice.utils.generator.GeneratorCodeForMysql;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class CodeCurServiceImpl implements ICodeCurService {

    private Logger logger=Logger.getLogger(this.getClass());
    
    @Autowired
    private CodeCurDao codecurDao;

    @Autowired
    private GeneratorCodeForMysql generatorCodeForMysql;

    @Override
    public Result getList(TCodeCur tCodeCur) {
        String sql="select * from db_sys.vt_code_cur";
        List<TCodeCur> list=codecurDao.getList(sql);
        if (EmptyUtil.isEmpty(list)) {
            return Result.success("没有查询到数据！", "");
        } else {
            return Result.success(list);
        }
    }

    
    @Override
    public Result insertList(List<TCodeCur> tCodeCurs) {
        int ret = codecurDao.insertList(tCodeCurs);
        if(ret==tCodeCurs.size()){
            return Result.success("添加成功！","");
        }else{
            throw new MyException(101, "添加失败！");
        }
    }

    
    @Override
    public Result deleteList(List<Integer> rowid) {
        int ret = codecurDao.deleteList(rowid);
        if(ret==rowid.size()){
            return Result.success("删除成功！","");
        }else{
            throw new MyException(101, "删除失败！");
        }
    }
    
    @Override
    public Result updateList(List<TCodeCur> tCodeCurs) {
        try {
            int ret = codecurDao.updateList(tCodeCurs);
            return Result.success("修改成功！","");
        }catch (Exception e){
            logger.info(e.getMessage(),e);
            throw new MyException(101, "修改失败！");
        }
    }
    
    
    @Override
    public Result insertCodeCur(TCodeCur tCodeCur) {
        try {
            int ret = codecurDao.insertCodeCur(tCodeCur);
            return Result.success("添加成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "添加失败！");
        }
    }

    @Override
    public Result updateCodeCur(TCodeCur tCodeCur) {
        try {
            int ret = codecurDao.updateCodeCur(tCodeCur);
            return Result.success("修改成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "修改失败！");
        }
    }

    @Override
    public Result deleteCodeCur(TCodeCur tCodeCur) {
        try {
            int ret = codecurDao.deleteCodeCur(tCodeCur);
            return Result.success("删除成功！", "");
        } catch (Exception e) {
            logger.info(e.getMessage(),e);
            throw new MyException(101, "删除失败！");
        }
    }


    /**
     * @author Another
     * @description :  生成编号序列号取值表
     * @date 2019/10/23 11:19:52
     * @param codeRule
     * @return com.another.exhibitioncommon.utils.result.Result
     * @version : 1.0
     */
    @Override
    public Result generatedNumber(TCodeRule codeRule) {
        return Result.success(generatorCodeForMysql.GeneratorCode(codeRule));
    }
}



